<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>

    <script>
        function myBrowser() {
            var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
             var str = "";
            if (userAgent.indexOf("OPR") > -1 || userAgent.indexOf("Opera") > -1) {//判断是否Opera浏览器
                str =  "Opera"
            } else if (userAgent.indexOf("Firefox") > -1) {//判断是否Firefox浏览器
                str =  "Firefox";
            }else if (userAgent.indexOf("Chrome") > -1) {
                str =  "Chrome";
            }else if (userAgent.indexOf("Safari") > -1) {//判断是否Safari浏览器
                str =  "Safari";
            }else {
                //其他
                str = "其他浏览器";
            }
            alert(userAgent);
            alert(str);
            return str;
        }
    </script>


</head>
<body>


<button onclick="myBrowser()"> 获取浏览器信息 </button>


</body>
</html>